<?php 
	if (function_exists('session_start')) session_start();
	
	
	if($_REQUEST["tmp"]) $_SESSION["tmp"] = $_REQUEST["tmp"];
	if($_REQUEST["nmr"]) $_SESSION["nmr"] = $_REQUEST["nmr"];
	
	
	
	require '../include/library.inc.php';
	
if($_GET["lang"])

	{
		
		
			$sql = "SELECT lang_id,code FROM language WHERE code ='".escape($_GET["lang"])."' ";
		
			$result_lang = query($sql);
		
			$row_lang = mysql_fetch_object($result_lang);
			if($row_lang)
			{
			$_SESSION["lang_id"] = $row_lang->lang_id;
			$_SESSION["lang"] = $row_lang->code;
			
			
			}
			
			

	}else{

		//redirect(HTML_BASE.'bg/');

	}

	if(!$_SESSION["lang"]  ){
	
		$sql = "SELECT lang_id,Name,code FROM language WHERE published  ORDER BY  	order_number LIMIT 1 ";
	
		$result_lang = query($sql);
	
		$row_lang = mysql_fetch_object($result_lang);		
		$_SESSION["lang_id"] = $row_lang->lang_id;		
		$_SESSION["lang"] = $row_lang->code;
		
		}
	
	
		if(!file_exists('../languages/'.$_SESSION["lang"].'.const.php'))
	
		{
	
			$_SESSION["lang_id"] = '1';
	
			$_SESSION["lang"] = 'bg';
	
		}

		require '../languages/'.$_SESSION["lang"].'.const.php';



			$tmp = 'home';
			if(!$_REQUEST["tmp"]) $tmp = 'page';
			if(!$_REQUEST["tmp"] || $_REQUEST["prm"]) $tmp = $_REQUEST["prm"];
			if($_REQUEST["tmp"]) $tmp = $_REQUEST["tmp"];
			
			if(!file_exists( 'tamplates/'.$tmp.'.tmp.php' )) 
			{
				$sql = "SELECT sef_url FROM pages WHERE published  AND sef_url = '".escape($tmp)."' ";
	
				$result_sef = query($sql);
				$row_sef = mysql_fetch_object($result_sef);
				
				if($row_sef){
					$sef_url = $tmp;
					$tmp = 'page';
				}else{
					$tmp = 'home';
				}
				
				
					
			}
			
			
			
			if($_REQUEST["nmr"]) $sef_url = $_REQUEST["nmr"];
			if($_REQUEST["nmr"]) $_GET["frompage"] = $_GET["nmr"];
			
			
	require 'tamplates/'.$tmp.'.tmp.php';
		

?>


